import { TypedUseSelectorHook, useSelector } from "react-redux";
import { registerReducers } from "apis/module/store";
import { RootState } from "apis/module/store";
import counterReducer from "./slices/counterSlice";

const add = {
  web: counterReducer,
};

// export type RootState = ReturnType<typeof rootReducer>;

registerReducers(add);

// type AppState = ReturnType<typeof persistedReducer>;

// 导出 state 类型，方便调用
// export type RootState = ReturnType<typeof rootReducer>;
// export type rootState = ReturnType<typeof store.getState>;

// // useAppSelector 和 useAppDispatch 代替 useSelector 和 useDispatch
// export const useAppSelector: TypedUseSelectorHook<rootState> = useSelector;
// export const useAppDispatch = () => useDispatch<TypeAppDispatch<AppState>>();

// export type appRootState = RootState &
//   Partial<{ web: ReturnType<typeof counterReducer> }>;

export type appRootState = RootState & {
  web: ReturnType<typeof counterReducer>;
};
export const useAppSelector: TypedUseSelectorHook<appRootState> = useSelector;
